package com.sh.data.engine.domain.api.run;

import com.sh.data.engine.common.enumDefinition.DataApiTaskTypeEnum;
import com.sh.data.engine.domain.api.model.domain.DataApiCallRecordDomain;
import com.sh.data.engine.domain.api.model.domain.rest.*;

import java.util.Map;

/**
 * @author: zigui.zdf
 * @description:
 * @date: 2021/3/10 9:52
 */
public class DataApiTaskExecutorFactory {

    public static DataApiTaskExecutor getExecutor(
        DataApiCallRecordDomain apiRecord,
        DataApiConfigInfoDomain configInfo,
        Object params,
        Long id) {

        if (null == configInfo) {
            return null;
        }
        Integer apiType = configInfo.getApiType();

        if (apiType.equals(DataApiTaskTypeEnum.REGIEST.getTypeCode())) {
            DataApiRegisterTaskConfigInfoDomain registerTaskConfigInfoDomain =
                (DataApiRegisterTaskConfigInfoDomain) configInfo;

            Map<String, String> map = (Map<String, String>) params;

            return new DataApiRegisterTaskExecutor(apiRecord, registerTaskConfigInfoDomain, map, id);
        }

        if (apiType.equals(DataApiTaskTypeEnum.INDEXLIB.getTypeCode())) {
            DataApiIndexTaskConfigInfoDomain dataApiIndexTaskConfigInfoDomain =
                (DataApiIndexTaskConfigInfoDomain) configInfo;

            Map<String, String> map = (Map<String, String>) params;

            return new DataApiIndexTaskExecutor(apiRecord, dataApiIndexTaskConfigInfoDomain, map, id);
        }

        if (apiType.equals(DataApiTaskTypeEnum.GUIDE.getTypeCode())) {
            DataApiGuideTaskConfigInfoDomain guideTaskConfigInfoDomain =
                (DataApiGuideTaskConfigInfoDomain) configInfo;

            Map<String, String> map = (Map<String, String>) params;

            return new DataApiGuideTaskExecutor(apiRecord, guideTaskConfigInfoDomain, map, id);
        }

        if (apiType.equals(DataApiTaskTypeEnum.SCRIPT.getTypeCode())) {
            DataApiScriptTaskConfigInfoDomain scriptTaskConfigInfoDomain =
                (DataApiScriptTaskConfigInfoDomain) configInfo;

            Map<String, String> map = (Map<String, String>) params;

            return new DataApiScriptTaskExecutor(apiRecord, scriptTaskConfigInfoDomain, map, id);
        }

        return null;
    }
}
